import request from "./http.js"

const accountInfo = wx.getAccountInfoSync();
const envWx = accountInfo.miniProgram.envVersion;
console.log("环境+++++++", envWx)
request.baseUrl = envWx == 'develop' || envWx == 'trial' ? "https://www.bcwd.cc/fq-server-test" : 'https://www.bcwd.cc/fq-server'
// request.baseUrl = "/blue"
// 请求开始之前做一些事情
request.beforeRequest = function (options) {
  const token = uni.getStorageSync("token")
  if (token) {
    options.header.AccessToken = token
  }
}

// 请求完成之后做一些事情
request.afterRequest = function (option) {
  if (option.statusCode == 200) {
    if (!option.data.code) {
      return option.data
    }
    if (option.data.code == 200) {
      return option.data
    } else {
      uni.showToast({
        title: option.data.msg,
        icon: 'none',
        duration: 1500,
      });
      return Promise.reject(option.data)
    }
  }
}
export default request
